package ModelLayer;
import java.util.*;
import java.text.*;

/**
 * Write a description of class Delivery here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Delivery
{
    private int deliveryID;
    private int customerID;
    private int employeeID;
    private String customerAddress;
    private String customerPhone;
    private int saleID;
    private String date;
    private HashMap<Integer, Integer> products;
    private double price;
   
    public Delivery(int deliveryID,int employeeID,int customerID,String customerAddress,String customerPhone, double price) {
        this.deliveryID = deliveryID;
        this.employeeID = employeeID;
        this.customerID = customerID;
        this.customerAddress = customerAddress;
        this.customerPhone = customerPhone;
        this.date = getDato();
        products = new HashMap<Integer,Integer>();
        this.price = calculatePrice(price);
    }
    
    public void addProduct(int productBarcode,int amount)
    {
        if(products.containsKey(productBarcode)) {
            int modification = amount;
            modification += products.get(productBarcode);
            products.remove(productBarcode);
            products.put(productBarcode,modification);
        } else {
            products.put(productBarcode, amount);
        }
    }
    
    public void removeProduct(int productBarcode, int amount)
    {
        if(products.containsKey(productBarcode) && products.get(productBarcode) > amount){
            int modification = products.get(productBarcode) - amount;
            products.remove(productBarcode);
            products.put(productBarcode, modification);
        }
    }
    
    private String getDato()
    {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy  HH:mm:ss");
        Date date = new Date();
        String dateString = dateFormat.format(date);
        return dateString;
    }
    
    public String getDate()
    {
        return date;
    }
    
    public HashMap<Integer,Integer> getProducts()
    {
        return products;
    }
    
    private double calculatePrice(double price)
    {
        double tempPrice = price;
        price = CustomerContainer.getInstance().findCustomerById(customerID).getDiscount();
        price = tempPrice * (price/100);
        tempPrice -= price;
        price = tempPrice;
        return price;
    }
    
    public int getDeliveryID()
    {
        return deliveryID;
    }
    
    public void setDeliveryID(int deliveryID)
    {
        this.deliveryID = deliveryID;
    }
    
    public int getSaleID()
    {
        return saleID;
    }
    
    public void setSaleID(int saleID)
    {
        this.saleID = saleID;
    }
    
    public int getCustomerID()
    {
        return customerID;
    }
    
    public void setCustomerID(int customerID)
    {
        this.customerID = customerID;
    }
    
    public String getCustomerPhone()
    {
        return customerPhone;
    }
    
    public void setCustomerPhone(String customerPhone)
    {
        this.customerPhone = customerPhone;
    }
    
    public String getCustomerAddress()
    {
        return customerAddress;
    }
    
    public void setCustomerAddress(String customerAddress)
    {
        this.customerAddress = customerAddress;
    }
   
    public int getEmployeeID()
    {
        return employeeID;
    }
    
    public void setEmployeeID(int employeeID)
    {
        this.employeeID = employeeID;
    }
    
    public double getPrice()
    {
        return price;
    }
}
